<template>
    <div>
        <input type="file" ref="fileRef" class="file" @change="todoStartUpload" />
        <slot :fileRef="fileRef"></slot>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { Http } from '../api/api';

const fileRef = ref<any>()
const emits: any = defineEmits()

const todoStartUpload = async () => {
    const file = fileRef.value.files[0]
    const data = new FormData()
    data.append('file', file)

    let res = await Http.uploadfile(data) as unknown as any;
    if (res.code == 200) {

        emits("getFilePath", res.path)
    }
}

defineExpose({
    fileRef
})

</script>

<style lang="scss" scoped>
.file {
    display: none;
    margin: 15px 0;
}
</style>